home *** CD-ROM | disk | FTP | other *** search
- /* strncpy.c From TC Bible page 291 Use strncpy to copy a specified number
- of characters of one string to another. */
-
- #include <stdio.h>
- #include <string.h>
- main()
- {
- size_t len;
- char str1[80], str2[80];
- printf("Enter a string: ");
- gets(str2);
- len = strlen(str2)/2;
- strncpy(str1, str2, len);
-
- /* Since '\0' is not appended automatically, we have to do so before
- printing string */
-
- str1[len] = '\0';
- printf("Halft the length of string copied. Result:\%s\n", str1);
- }